/*
**************************************************************************************
*Myriad Engine                                                                       *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
package leola.backend.interpreter;

/**
 * Scope which can be associated with a parent scope (i.e., is can be embedded).
 * 
 * @author Tony
 *
 */
public class Scope {

	/**
	 * Embedded scope
	 */
	private boolean embedded;
	
	/**
	 * Is Class
	 */
	private boolean isClassScope;
	
	/**
	 * Symbol table
	 */
	private SymbolTable symbolTable;

	/**
	 * Class name
	 */
	private String className;
	
	/**
	 * @param embedded
	 * @param symbolTable
	 */
	public Scope(boolean isClassScope, String className, boolean embedded, SymbolTable symbolTable) {
		this.isClassScope = isClassScope;
		this.className = className;
		this.embedded = embedded;
		this.symbolTable = symbolTable;
	}
	
	/**
	 * @param isClassScope
	 * @param embedded
	 */
	public Scope(boolean isClassScope, String className,  boolean embedded) {
		this(isClassScope, className, embedded, new SymbolTable());
	}
	
	/**
	 * @param embedded
	 */
	public Scope(boolean embedded) {
		this(false, null, embedded, new SymbolTable());
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "[ Embedded: " + this.embedded + " : ClassName: " + this.className + " : " + this.symbolTable + " ]" ;
	}
	
	/**
	 * @return the symbolTable
	 */
	public SymbolTable getSymbolTable() {
		return symbolTable;
	}
	
	/**
	 * @return the embedded
	 */
	public boolean isEmbedded() {
		return embedded;
	}
	
	/**
	 * @return the className
	 */
	public String getClassName() {
		return className;
	}
	
	/**
	 * @param isEmbedded
	 * @return returns the previous state
	 */
	public boolean setEmbedded(boolean isEmbedded) {
		boolean previous = this.embedded;
		this.embedded = isEmbedded;
		return previous;
	}
	
	/**
	 * @return the isClassScope
	 */
	public boolean isClassScope() {
		return isClassScope;
	}
	
	/**
	 * @return a deep copy of this scope
	 */
	public Scope clone() {
		return new Scope(this.isClassScope, this.className, this.embedded, this.symbolTable.clone());
	}
	
	/**
	 * @return a deep copy of this scope
	 */
	public Scope shallowClone() {
		return new Scope(this.isClassScope, this.className, this.embedded, this.symbolTable.shallowClone());
	}
}
